#include "bit.h"

int nbit()
{
    int n;
    long long i = 1L;
    for (n = 0; i != 0; n++)
        i = i << 1;
    return n;
}

int k_bit_of_i(long long i, int k, int n)
{
    int l = nbit();
    k = l - n + k;
    i = i >> (l - k);
    i = i & 1;
    return i;
}


long long set_k_bit_i_0(long long i, int k, int n)
{
    int l = nbit();
    k = l - n + k;
    long long mask = 1L;
    mask = mask << (l - k);
    i = i & (~mask);
    return i;
}


long long set_k_bit_i_1(long long i, int k, int n)
{
    int l = nbit();
    k = l - n + k;
    long long mask = 1L;
    mask = mask << (l - k);
    i = i | mask;
    return i;
}

complexd myrandom()
{
    double r, i;
    r = my_omp_rand();
    i = my_omp_rand();
    complexd a(r,i);
    return a;
}
